package com.safeneeds.util.log.support;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.safeneeds.util.log.ALogFactory;
import com.safeneeds.util.log.ILogLeval;
import com.safeneeds.util.log.ILogMessage;

/**
 * 日志内容
 * 
 * @version 1.0
 * @date 2012-09-01
 * @author DWZ框架组
 */
public class LogMessage implements ILogMessage {

	/* 日志查询索引 */
	private String logKey;
	/* 记录人 */
	private String userId;
	/* 日志内容 */
	private String logInfo;
	/* 日志类型 */
	private String logModule;
	/* 日志级别 */
	private ILogLeval logLeval;

	private static final SimpleDateFormat YYYYMMDD_FORMAT = new SimpleDateFormat(
			"yyMMdd");
	private static final SimpleDateFormat HHMMSS_FORMAT = new SimpleDateFormat(
			"HH:mm:ss");

	public LogMessage() {
	}

	public LogMessage(String logInfo) {
		this.logInfo = logInfo;
	}

	public LogMessage(String logModule, String logInfo) {
		this.logModule = logModule;
		this.logInfo = logInfo;
		this.logLeval = ALogFactory.LOG_LEVAL_INFO;
	}

	public LogMessage(String logModule, String logKey, String logInfo) {
		this.logModule = logModule;
		this.logKey = logKey;
		this.logInfo = logInfo;
		this.logLeval = ALogFactory.LOG_LEVAL_INFO;
	}

	public LogMessage(ILogLeval logLeval, String logModule, String logKey,
			String logInfo) {
		this.logModule = logModule;
		this.logKey = logKey;
		this.logInfo = logInfo;
		this.logLeval = logLeval;
	}

	public LogMessage(ILogLeval logLeval, String logModule, String logKey,
			String logInfo, String userId) {
		this.logModule = logModule;
		this.logKey = logKey;
		this.logInfo = logInfo;
		this.logLeval = logLeval;
		this.userId = userId;
	}

	public String getLogDate() {
		return YYYYMMDD_FORMAT.format(new Date());
	}

	public String getLogInfo() {
		return null == logInfo ? " " : logInfo;
	}

	public String getLogKey() {
		return null == logKey ? " " : logKey;
	}

	public ILogLeval getLogLeval() {
		return null == logLeval ? ALogFactory.LOG_LEVAL_INFO : logLeval;
	}

	public String getLogModule() {
		return null == logModule ? " " : logModule;
	}

	public String getLogTime() {
		return HHMMSS_FORMAT.format(new Date());
	}

	/**
	 * 获取日志记录人
	 * 
	 * @return
	 */
	public String getLogUser() {
		return this.userId;
	}

	@Override
	public String toString() {
		
		return getLogLeval() +": " +getLogInfo();
		
//		return getLogLeval() + "：" + getLogUser() + "--[" + getLogDate() + " "
//				+ getLogTime() + "]--" + getLogModule() + "--" + getLogKey()
//				+ ":" + getLogInfo();
	}

}
